"""
用户认证URL配置
"""
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt.views import TokenRefreshView
from . import views
from .admin_views import (
    UserManageViewSet, PermissionViewSet,
    RolePermissionViewSet, LoginLogViewSet, TeacherViewSet
)
from .views import PersonalCenterViewSet, SystemSettingsViewSet

# 创建路由器
router = DefaultRouter()
router.register(r'users', UserManageViewSet, basename='user-manage')
router.register(r'teachers', TeacherViewSet, basename='teacher')
router.register(r'permissions', PermissionViewSet, basename='permission')
router.register(r'role-permissions', RolePermissionViewSet, basename='role-permission')
router.register(r'login-logs', LoginLogViewSet, basename='login-log')
router.register(r'personal-center', PersonalCenterViewSet, basename='personal-center')
router.register(r'system-settings', SystemSettingsViewSet, basename='system-settings')

urlpatterns = [
    # 认证相关
    path('login/', views.CustomTokenObtainPairView.as_view(), name='login'),
    path('register/', views.register, name='register'),
    path('logout/', views.logout, name='logout'),
    path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),

    # 用户资料
    path('profile/', views.profile, name='profile'),
    path('profile/update/', views.update_profile, name='update_profile'),
    path('change-password/', views.change_password, name='change_password'),
    path('user-permissions/', views.user_permissions, name='user_permissions'),
    path('permissions/', views.user_permissions, name='permissions'),  # 兼容前端调用

    # 管理员API（使用ViewSet路由）
    path('', include(router.urls)),
]
